﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.IO;
using DataAccessEntLib;


public partial class Classfied_Cld_Home : System.Web.UI.Page
{
    BO.Ad bo = new BO.Ad();
    BLL.AdMagnager bll = new BLL.AdMagnager();
    RegistrationData regdata = new RegistrationData();
    string abc = string.Empty;
    BusinessLogic busin = new BusinessLogic();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["User"] != null)
            {
                regdata = (RegistrationData)Session["User"];
            }
            else
            {
                busin.checkcookies_ForLogin(Request.Url.ToString());
            }
            BindCategoryDetails();
            //if (!object.Equals(Request.Cookies["countryid"], null))
            //{
            //    abc = string.Empty;
            //    HttpCookie myCookie = Request.Cookies.Get("countryid");
            //    Response.Cookies.Add(myCookie);
            //    abc = myCookie.Value;
            //}
            //else
            //{
            //    hdnshow.Value = "1";

            //}
            // if (abc != string.Empty)
            //{
            //    BindLatest(1, "1");
            //    BindLatest(2, "1");
            //    BindLatest(3, "1");
            //    BindPopularItems(4);
            //    // BindCategory();
            //    BindCategoryDetails("1");
            //}

        }
    }

    //protected void BindCategory()
    //{
    //    DataSet ds = new DataSet();
    //    ds = bll.BindAdCategoryMaster();
    //    if (ds.Tables.Count > 0)
    //    {
    //        if (ds.Tables[0].Rows.Count > 0)
    //        {
    //            //rptCategory.DataSource = ds;
    //            //rptCategory.DataBind();
    //            System.Text.StringBuilder sb = new System.Text.StringBuilder();

    //            foreach (DataRow dr in ds.Tables[0].Rows)
    //            {
    //                sb.Append("<li><a href='javascript:void();' > " + Convert.ToString(dr["AdCategory"]) + "</a></li>");
    //            }
    //            ulList.InnerHtml = sb.ToString();
    //        }
    //    }
    //}

    ////protected void BindLatest(int TypeID)
    ////{
    ////    divLatest.InnerHtml = string.Empty;
    ////    IDataReader dr;
    ////    bo.TypeID = TypeID;
    ////    dr = bll.SelectLatestTopFeaturedAd(bo);
    ////    if (dr != null)
    ////    {
    ////        divLatest.InnerHtml = "<ul>";
    ////        while (dr.Read())
    ////        {
    ////            divLatest.InnerHtml += "<li><div class='porduct_img'><img src='" + dr["ImagePath"].ToString() + "' border='0'></div><p>" + dr["AdTitle"].ToString() + "</p></li>";
    ////        }
    ////        divLatest.InnerHtml += "</ul>";
    ////    }
    ////    dr.Close();
    ////}



    ////Header
    //protected void BindLatest(int TypeID, string CountryID)
    //{
    //    //divLatest.InnerHtml = string.Empty;
    //    IDataReader dr;
    //    bo.TypeID = TypeID;
    //    bo.Country = CountryID;
    //    dr = bll.SelectLatestTopFeaturedAd(bo);
    //    if (dr != null)
    //    {
    //        if (TypeID == 1)
    //        {
    //            divLatest.InnerHtml = "<ul>";
    //            while (dr.Read())
    //            {
    //                divLatest.InnerHtml += "<li><div class='porduct_img'><img src='" + dr["ImagePath"].ToString() + "' border='0'></div><p><a href='Cld-Ad-Details.aspx?AdID=" + dr["AdID"].ToString() + "' style='color:#666'>" + dr["AdTitle"].ToString() + "</a></p></li>";
    //            }
    //            divLatest.InnerHtml += "</ul>";
    //        }
    //        if (TypeID == 2)
    //        {
    //            divLatest1.InnerHtml = "<ul>";
    //            while (dr.Read())
    //            {
    //                divLatest1.InnerHtml += "<li><div class='porduct_img'><img src='" + dr["ImagePath"].ToString() + "' border='0'></div><p><a href='Cld-Ad-Details.aspx?AdID=" + dr["AdID"].ToString() + "' style='color:#666'>" + dr["AdTitle"].ToString() + "</a></p></li>";
    //            }
    //            divLatest1.InnerHtml += "</ul>";
    //        }
    //        if (TypeID == 3)
    //        {
    //            divLatest2.InnerHtml = "<ul>";
    //            while (dr.Read())
    //            {
    //                divLatest2.InnerHtml += "<li><div class='porduct_img'><img src='" + dr["ImagePath"].ToString() + "' border='0'></div><p><a href='Cld-Ad-Details.aspx?AdID=" + dr["AdID"].ToString() + "' style='color:#666'>" + dr["AdTitle"].ToString() + "</a></p></li>";
    //            }
    //            divLatest2.InnerHtml += "</ul>";
    //        }
    //    }
    //    dr.Close();
    //}

    ////Side Header
    //protected void BindPopularItems(int TypeID)
    //{
    //    IDataReader dr;
    //    bo.TypeID = TypeID;
    //    dr = bll.SelectLatestTopFeaturedAd(bo);
    //    if (dr != null)
    //    {
    //        divPopularItems.InnerHtml = "<h1><img src='images/popular_icon.png' height='24' width='24' border='0' align='absmiddle'><span class='ml5px'>Popular Items</span></h1>";
    //        while (dr.Read())
    //        {
    //            divPopularItems.InnerHtml += "<div class='popularitem'><div class='itemimg'><img src='" + dr["ImagePath"].ToString() + "' border='0'></div><div class='itemdetails'><p><a href='Cld-Ad-Details.aspx?AdID=" + dr["AdID"].ToString() + "' style='color:#666'>" + dr["AdTitle"].ToString() + "</a></p></div><div class='clear'></div></div>";
    //        }
    //        divPopularItems.InnerHtml += "";
    //    }
    //    dr.Close();
    //}

    ////protected void lnkLatest_Click(object sender, EventArgs e)
    ////{
    ////    lnkHots.CssClass = "";
    ////    lnkLatest.CssClass = "active";
    ////    lnkFeatured.CssClass = "";
    ////    BindLatest(1);
    ////}

    ////protected void lnkHots_Click(object sender, EventArgs e)
    ////{
    ////    lnkHots.CssClass = "active";
    ////    lnkLatest.CssClass = "";
    ////    lnkFeatured.CssClass = "";
    ////    BindLatest(2);
    ////}

    ////protected void lnkFeatured_Click(object sender, EventArgs e)
    ////{
    ////    lnkHots.CssClass = "";
    ////    lnkLatest.CssClass = "";
    ////    lnkFeatured.CssClass = "active";
    ////    BindLatest(3);
    ////}


    protected void BindCategoryDetails()
    {
        DataSet dsSubCat = new DataSet();
        dsSubCat = bll.Select_AllSubCategoryAds();
        if (dsSubCat.Tables.Count > 0)
        {
            if (dsSubCat.Tables[0].Rows.Count > 0)
            {
                //lstSubCategoryDetails.Visible = true;
                //lstSubCategoryDetails.DataSource = dsSubCat;
                //lstSubCategoryDetails.DataBind();
                //<ul>
                //      <li>
                //          <h3><%# Eval("SubCategory")%> <span class="green">(25)</span></h3>
                //      </li>
                //      <li  style="width:450px;">
                //          <p><%# Eval("SubCategoryDesc")%></p>
                //          <a href="Cld-List.aspx?ID=<%# Eval("SubCategoryID")%>" class="moreview">View More</a>
                //      </li>
                //  </ul>  

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (DataRow drmain in dsSubCat.Tables[0].Rows)
                {
                    DataRow[] drCats = dsSubCat.Tables[1].Select("AdCategoryID= " + drmain["AdCategoryID"].ToString());
                    if (drCats.Length > 0)
                    {
                        DataTable dt = new DataTable();
                        dt = drCats.CopyToDataTable();
                        sb.Append("<div  id='ulSubCat-" + drmain["AdCategoryMenuId"].ToString() + "' style='display:none;'><ul class='sublist_nav'>");
                        foreach (DataRow dr in dt.Rows)
                        {
                            sb.Append("<li><a href='/Classified/Cld-List.aspx?SubCatID=" + dr["SubCategoryID"].ToString() + "' >" + dr["SubCategory"] + "<span class='green'>(" + dr["TotalAds"] + ")</span> </a></li> ");
                        }
                        sb.Append("</ul></div>");
                    }
                }
                divsubcatDetails.InnerHtml = sb.ToString();

            }
        }
    }


    protected void imgSearch_Click(object sender, ImageClickEventArgs e)
    {
        if (AdTitle.Value.Trim() != string.Empty)
        {
            Session["AdTitle"] = AdTitle.Value;
            Response.Redirect("~/Classified/Cld-Search.aspx");
        }
    }
}